package com.ttg.common.entities;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.ttg.common.utils.JsonUtils;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @author 上饶银行 统一任务调度平台 结果类
 * {"OUT_CODE": "0","OUT_MESG": "执行成功"}
 * {"OUT_CODE": "1","OUT_MESG": "执行中"}
 * {"OUT_CODE": "9","OUT_MESG": "执行失败，数据文件格式不符！"}
 * @version 1.0
 * @Description 公共返回模型
 * @date 2020/11/6 16:19
 */
@Data
@NoArgsConstructor
public class JobResult {

    @JsonProperty("OUT_CODE")
    private String outCode;

    @JsonProperty("OUT_MESG")
    private String outMest;

    public JobResult(String outCode, String outMest) {
        this.outCode = outCode;
        this.outMest = outMest;
    }


    /**
     * 成功
     */
    public static JobResult success() {
        return new JobResult("0", "执行成功");
    }

    /**
     * 返回默认失败（执行失败）
     */
    public static JobResult defaultFail() {

        return JobResult.fail(null);
    }

    public static JobResult fail(String failReason) {
        if (StringUtils.isBlank(failReason)) {
            return new JobResult("9", "执行失败");
        }
        return new JobResult("9", failReason);
    }

    @Override
    public String toString() {
        return JsonUtils.objectToJson(this);
    }
}
